function addgoods(goods_id) {
    $.ajax({
        url: 'shop.do',
        type: 'POST',
        data:{goods_id:goods_id},
    });
    alert("加入购物车成功");
}
function shop_car() {
    $.ajax({
        url: 'shop_car.do',
        type: 'POST',
        async:false,
    });
    window.location.href="shop_car.jsp";
}
function setgoods_type(goods_type) {
    $.ajax({
        url: 'setgoods_type.do',
        type: 'POST',
        data: {goods_type:goods_type},
        success:function () {
            window.location.href="food.jsp";
        }
    });
}
layui.use(['carousel', 'form'], function(){
    var carousel = layui.carousel
        ,form = layui.form;
    //图片轮播
    carousel.render({
        elem: '#heder01'
        ,width: 'margin: 0 auto'
        ,height: '440px'
        ,interval: 4000
    });
});
// var ggRoll = {
//     roll: document.getElementById("roll"),
//     speed: 30,
//     statusX: 1,
//     statusY: 1,
//     x: 50,
//     y: 200,
//     winW: document.documentElement.clientWidth - document.getElementById("roll").offsetWidth,
//     winH: document.documentElement.clientHeight - document.getElementById("roll").offsetHeight,
//     Go: function() {
//         this.roll.style.left = this.x + 'px';
//         this.roll.style.top = this.y + 'px';
//
//         this.x = this.x + (this.statusX ? -1 : 1)
//         if (this.x < 0) {
//             this.statusX = 0
//         }
//         if (this.x > this.winW) {
//             this.statusX = 1
//         }
//
//         this.y = this.y + (this.statusY ? -1 : 1)
//         if (this.y < 0) {
//             this.statusY = 0
//         }
//         if (this.y > this.winH) {
//             this.statusY = 1
//         }
//     }
// }
var interval = setInterval("ggRoll.Go()", ggRoll.speed);
ggRoll.roll.onmouseover = function() {
    clearInterval(interval)
};
ggRoll.roll.onmouseout = function() {
    interval = setInterval("ggRoll.Go()", ggRoll.speed)
};

var btnx = document.getElementById('btnx');
var roll = document.getElementById('roll');
btnx.onclick = function(){
    roll.style.display = 'none';
}
var websocket=null;
if('WebSocket' in window){
    websocket=new WebSocket('ws://localhost:8080<%=path%>/webSocket');
}else{
    alert("该浏览器不支持websocket");
}
websocket.onopen=function (event) {
    console.log('建立链接');
}
websocket.onclose=function (event) {
    console.log('链接关闭');
}
websocket.onmessage=function (event) {
    console.log('收到消息'+event.data)
    //消息提醒
}
websocket.onerror=function (event) {
    alert("发生错误");
}
window.onbeforeunload=function () {
    websocket.close();
}